from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# 配置Chrome选项
options = Options()
prefs = {
    "profile.managed_default_content_settings.images": 2,  # 禁止图片加载
    "profile.managed_default_content_settings.video": 2  # 禁止视频加载
}
options.add_experimental_option("prefs", prefs)

# 初始化Chrome浏览器
driver = webdriver.Chrome(options=options)

try:
    # 访问百度首页
    driver.get("https://www.baidu.com")
    driver.maximize_window()

    # 截图保存
    driver.save_screenshot("baidu_no_image_video.png")
    print("截图已保存")

except Exception as e:
    print(f"操作失败：{e}")

finally:
    # 关闭浏览器
    driver.quit()